﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;


namespace AtlasGis
{
    
   
    public partial class MainWindow : Window
    {

        public static bool cntrlIn = false;
        
        private string moveEnterLabelBackColor = "#FF2231A7";
        private string clickLabelBackColor = "#FF4509A9";
        private string strLblName = "";

        private System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
        
        private Brush getColor(string color)
        {
            BrushConverter bc = new BrushConverter();
            Brush brush = (Brush)bc.ConvertFrom(color);
            return brush;
        }
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            if (cntrlIn)
            {
                MessageBox.Show("In");
                cntrlIn = false;
            }
        }
        public MainWindow()
        {
            InitializeComponent();
            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(100);
            dispatcherTimer.Start();
        }
      
      
     
        private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }
        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        { 
            if (this.WindowState != WindowState.Maximized)
            {
                SystemCommands.MaximizeWindow(this);                
            }
            else
            {
                SystemCommands.RestoreWindow(this);
            }
            
        }


        private void btnMin_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	this.WindowState = WindowState.Minimized;
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Label_MouseEnter(object sender, MouseEventArgs e)
        {
            Label moveEnterLabel = sender as Label; 
          
            if (moveEnterLabel != null)
            {
                if (moveEnterLabel.Name != strLblName)
                {
                    moveEnterLabel.Background = getColor(moveEnterLabelBackColor);
                }
                
            }
        }

        private void Label_MouseLeave(object sender, MouseEventArgs e)
        {
            Label moveLeave = sender as Label;

            if (moveLeave != null)
            {               
                if (moveLeave.Name != strLblName)
                {
                    moveLeave.Background = new SolidColorBrush(Colors.Transparent);
                }
                               
            }

        }

        private void Label_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Label mouseDown = sender as Label;
            //MessageBox.Show(" Mouse click" + moveEnterLabel.Background + " vs " + getColor(clickLabelBackColor));            
            if (mouseDown != null)
            {
                if (strLblName.CompareTo("") != 0)
                {
                    var lbl = this.FindName(strLblName);
                    if (lbl != null)  ((Label)lbl).Background = new SolidColorBrush(Colors.Transparent);
                }

                strLblName = mouseDown.Name;
                mouseDown.Background = getColor(clickLabelBackColor);
                loadUC(); 
               
            }
        }
        private void loadUC()
        {          
                lblTitle.Content = ((Label)this.FindName(strLblName)).Content;
                switch (strLblName)
                {
                    case "lblBDHC":
                        dcpMap.Children.Clear();
                        ucBD_hanhchinh ucHanhChinh = new ucBD_hanhchinh();
                        dcpMap.Children.Add(ucHanhChinh);
                        break;

                    case "lblThi":
                        dcpMap.Children.Clear();
                        ucThiTN ucThi = new ucThiTN();
                        dcpMap.Children.Add(ucThi);
                        break;

                    case "lblDS":
                        dcpMap.Children.Clear();
                        ucXemSach ucXS = new ucXemSach();
                        dcpMap.Children.Add(ucXS);
                        break;
                }
                        
        }

        private void lblTitle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }
     
       

    
       
    }
}
